package controllers

import (
	"encoding/json"
	"fmt"
)

type LogController struct {
	BaseController
}

func (c *UserController) GetAllLog() {
	obj := c.GetString("obj")

	var data map[string]interface{}
	if err := json.Unmarshal([]byte(obj), &data); err != nil {
		c.writeError(err)
		return
	}
	pageIndex := int64(data["pageIndex"].(float64))
	pageSize := int64(data["pageSize"].(float64))
	accoutName := fmt.Sprint(data["accoutName"])
	appName := fmt.Sprint(data["appName"])

	count, users, err := logDao.GetLogs(accoutName, appName, pageIndex, pageSize)
	if err != nil {
		c.writeError(err)
		return
	}

	c.Data["json"] = Response{
		Data:    users,
		Total:   count,
		Success: true,
	}

	c.ServeJSON()
}
